import Vue from "vue";
import VueRouter from "vue-router"

Vue.use(VueRouter);

import Login from "../views/Login/index"

const routes = [
    {
        path: "/",
        redirect: "/login"
    },
    {
        name: "login",
        path: "/login",
        component: Login,
        meta: {
            title: "登录"
        }
    },
    {
        name: "main",
        path: "/main",
        component: () => import("../views/Main/index"),
        redirect: "/main/home",
        children: [
            {
                name: "home",
                path: "home",
                component: () => import("../views/Home/index"),
                meta: {
                    title: "商城首页"
                }
            },
            {
                name: "cates",
                path: "cates",
                component: () => import("../views/Cates/index"),
                meta: {
                    title: "商品分类"
                },
                children: [
                    {
                        name: "list",
                        path: "list",
                        component: () => import("../views/Cates/catelist"),
                    },
                ]
            },
            {
                name: "scar",
                path: "scar",
                component: () => import("../views/ShopCar/index"),
                meta: {
                    title: "购物车"
                }
            },
            {
                name: "mine",
                path: "mine",
                component: () => import("../views/Mine/index"),
                meta: {
                    title: "我的"
                }
            },
            {
                name: "goodsdetail",
                path: "goodsdetail",
                component: () => import("../views/Goods/index"),
                meta: {
                    title: "商品详情"
                }
            },
        ]
    }
]
const router = new VueRouter({
    mode: "history",
    linkActiveClass: "active",
    routes,

})
// 全局前置守卫
router.beforeEach((to, from, next) => {
    console.log(to, from)
    next()
})

export default router;